package com.guiwu.gteway.industryapp.util;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class ApiJsonUtil {


    /**
     * 返回data里的jsonElement
     *  {
     *   "error": "succ",
     *   "data": [
     *              {
     *                  "code": "483711"    //短信6位随机验证码
     *              }
     *         ],
     *   "errno": 0
     * }
     *
     *
     * @param jsonString
     * @return
     */
    public static JsonResult getData(String jsonString) {
        JsonResult result;
        JsonObject jb = new JsonParser().parse(jsonString).getAsJsonObject();
        int errorCode = jb.get("errno").getAsInt();
        if (errorCode == 0){
            result = new JsonResult("Success",jb.get("data"));
        }else {
            result = new JsonResult(jb.get("error").getAsString(),null);
        }
        return result;
    }
}
